package xj.graph2d.command;

import xj.graph2d.BoxGroup;
import xj.graph2d.SimpleDrawDocument;
import xj.graph2d.SimpleDrawView;

public class AlignmentCommand extends DeltaCommand {

  public AlignmentCommand(SimpleDrawView view, SimpleDrawDocument doc,
			  BoxGroup box) {
    super(view, doc, box);
    this.box = box;
    start = box.getAlignment();
  }

  @Override
  protected void forward() {
    if (end != -1) {
      box.setAlignment(end);
      box.align();
      box.calculateBounds();
    }
  }

  @Override
  protected void backward() {
    end = box.getAlignment();
    if (start != -1) {
      box.setAlignment(start);
      box.align();
      box.calculateBounds();
    }
  }

  protected BoxGroup box;

  protected int start = -1;

  protected int end = -1;

}
